package db

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"project2/g"
)

func InitDb() {
	dsn := "root:12liumingtai@tcp(127.0.0.1:3306)/erp?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})

	if err != nil {
		fmt.Println(err)
		fmt.Println("数据库连接错误")
	}
	//db.SingularTable(true)
	//db.LogMode(true)

	fmt.Println("链接Mysql成功")
	g.Db = db

}
